package com.taoye.thread;

public class Demo08 {
	public static void main(String[] args) throws InterruptedException {
		User u = new User();
		System.out.println("修改前user:" + u);
		Demo08Thread t = new Demo08Thread(u);
		t.start();
		Thread.sleep(500);// 在外面把线程以外结束掉
		t.stop();
		System.out.println("修改后user:" + u);
		System.out.println(t.isAlive());
	}
}

class User {
	private String name = "a";
	private String pwd = "aa";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", pwd=" + pwd + "]";
	}
}

class Demo08Thread extends Thread {

	private User user;

	public Demo08Thread(User user) {
		this.user = user;
	}

	@Override
	public void run() {
		try {
			// 先修改用户名，暂停五秒后再修改用户密码
			user.setName("b");
			Thread.sleep(5000);
			user.setPwd("bb");
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ThreadDeath e) {
			System.out.println("线程被意外停止了");
		}
		System.out.println("线程执行结束了");
	}
}